﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TFSTools.TFSLibrary;

namespace TFSTools.TestManagement.TestCaseReview
{
    public class OptionsDataContext
    {
        private TFSConnection connection;
        private string stepCommentFieldReferenceName;

        public OptionsDataContext(TFSConnection tfsConnection)
        {
            this.connection = tfsConnection;
            var projectSettings = ProjectSettings.GetFromSettings();
            this.stepCommentFieldReferenceName = projectSettings[tfsConnection].StepCommentFieldReferenceName; 
        }

        public string StepCommentFieldReferenceName
        {
            get { return this.stepCommentFieldReferenceName; }
            set { this.stepCommentFieldReferenceName = value; }
        }

        public bool Save()
        {
            TFSFieldDefinition fieldDef = null;
            
            try
            {
                fieldDef = this.connection.WorkItemStore.GetFieldDefinitionFromReferenceName(this.stepCommentFieldReferenceName);
            }
            catch 
            {
            }

            if (fieldDef == null)
            {
                return false;
            }

            var projectSettings = ProjectSettings.GetFromSettings();
            projectSettings.SaveToSettings(this.connection, this.stepCommentFieldReferenceName, null);
            return true;
        }


    }
}
